const { sequelize } = require('../config/database');
const Weather = require('./Weather');
const WeatherForecast = require('./WeatherForecast');
const Geocode = require('./Geocode');
const Poi = require('./Poi');
const Route = require('./Route');
const News = require('./News');
const User = require('./User');

// 定义模型关联关系
const defineAssociations = () => {
  // 天气和天气预报的关联（可选）
  Weather.hasMany(WeatherForecast, {
    foreignKey: 'city',
    sourceKey: 'city',
    as: 'forecasts'
  });
  
  WeatherForecast.belongsTo(Weather, {
    foreignKey: 'city',
    targetKey: 'city',
    as: 'currentWeather'
  });
};

// 初始化模型关联
defineAssociations();

module.exports = {
  Weather,
  WeatherForecast,
  Geocode,
  Poi,
  Route,
  News,
  User,
  sequelize
}; 